You can easily perform array with array arithmetic, or scalar with array arithmetic. Let's see some examples:
import numpy as np
arr = np.arange(0,10)
arr + arr
arr * arr
arr - arr
# Warning on division by zero, but not an error!
# Just replaced with nan
arr/arr
# Also warning, but not an error instead infinity
1/arr
arr**3
Numpy comes with many universal array functions, which are essentially just mathematical operations you can use to perform the operation across the array. Let's show some common ones:
#Taking Square Roots
np.sqrt(arr)
#Calcualting exponential (e^)
np.exp(arr)
np.max(arr) #same as arr.max()
np.sin(arr)
np.log(arr)
Suppose you want to calculate the sum of all the columns, the you can make use of axis.
a = np.array([(1,2,3),(3,4,5)])
a
# Add columns
print(a.sum(axis = 0))
so, as you see above sum of all columns has added where 1+3=4, 2+4=6,3+5=8.
# Add rows
print(a.sum(axis = 1))
so, similarly as you can see if you replace the axis by 1 then it prints [6,12], where all rows get added.
That's all we need to know for now.. see you on next chapter..